Page({
 

  /**

   * 页面的初始数据

   */

  data: {
    addressList:[{
      consignee:1,
      mobile:1221,
      address:'ahsfdghasd',
      statu:false
    },{
      consignee:2,
      mobile:1221,
      address:'ahsfdghasd',
      statu:false
    },{
      consignee:3,
      mobile:1221,
      address:'ahsfdghasd',
      statu:false
    }]

  },

  /**

   * 生命周期函数--监听页面加载

   */

  onLoad: function (options) {
    var arr = wx.getStorageSync('addressList') || [];
    console.log(arr)
    this.setData({
      addressList: arr
    });

  },
  /**

   * 生命周期函数--监听页面显示

   */

  onShow: function () {
    this.onLoad();

  },

  addAddress:function(){
    wx.navigateTo({ url: '../changeAddress/changeAddress' });

  },
  default:function(e){
    let addr=this.data.addressList;
    for(let i=0;i<this.data.addressList.length;i++){
        addr[i].statu=false;
    }
    addr[e.detail.value].statu=true;
    wx.setStorageSync('addressList', addr)
  },
  /* 删除item */

  delAddress: function (e) {
    this.data.addressList.splice(e.currentTarget.dataset.id, 1);

    // 更新data数据对象  

    if (this.data.addressList.length > 0) {
      this.setData({
        addressList: this.data.addressList

      })

      wx.setStorageSync('addressList', this.data.addressList);

    } else {
      this.setData({
        addressList: this.data.addressList

      })

      wx.setStorageSync('addressList', []);

    }

  }

})

